In [1]:
import numpy as np
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from pydelft.grd_dep import grd, dep
from pydelft.bnd import bnd
import re
from PyQt4 import QtGui
import sys
import os
import pandas as pd
% matplotlib inline

Get the coordinates of the ends of each boundary section

Read a .bnd file, return coordinates of the end points. I'm making this so I can apply boundary conditions from a completely different model and grid.


In [2]:
fname = r'i:\Japan\Data\Sendai\T3\create_riemann\testing\run7\natori_10_v2.bnd'
bounds = bnd(fname)
bounds.read_grd(r'i:\Japan\Data\Sendai\T3\create_riemann\testing\run7\natori_10_v1.0.grd')
bounds.get_xy()


loaded i:\Japan\Data\Sendai\T3\create_riemann\testing\run7\natori_10_v1.0.grd

In [3]:
b_plot = plt.plot([bounds.x1,bounds.x2],[bounds.y1,bounds.y2],'ko-')


Get the indices of these boundary sections on a different grid

Load a different grid. Input the x,y coordinates of the boundaries to find the closest m,n indices on different grid (which is in a different projection).


In [4]:
natori_5 = grd(r'i:\Japan\Modeling\T3_Delft\grd_enc\natori_5.grd')
mn1 = natori_5.get_mn(bounds.x1, bounds.y1, 2452,4326)
mn2 = natori_5.get_mn(bounds.x2, bounds.y2, 2452,4326)

In [5]:
for i in range(0, np.size(bounds.x1)-1):
    print('%s\t(%.6f, %.6f)\t(%.6f, %.6f)\n\t(%s\t%s\n' 
          % (bounds.name[i], bounds.x1[i],bounds.y1[i],
             bounds.x2[i],bounds.y2[i], mn1[i], mn2[i]))


North1	(140.901275, 38.159970)	(140.901553, 38.159970)
	([748, 489]	[748, 494]

North2	(140.932725, 38.159970)	(140.932817, 38.159970)
	([749, 1040]	[749, 1042]

North3	(140.940865, 38.159970)	(140.941235, 38.159970)
	([749, 1183]	[749, 1190]

North4	(140.943455, 38.159970)	(140.944658, 38.159970)
	([749, 1229]	[749, 1250]

North5	(140.944935, 38.159970)	(140.945675, 38.159970)
	([749, 1254]	[749, 1267]

North6	(140.948450, 38.159970)	(140.949560, 38.159970)
	([749, 1316]	[749, 1336]

North7	(140.955572, 38.159970)	(140.958902, 38.159970)
	([749, 1441]	[749, 1499]

North8	(140.958995, 38.159970)	(140.962325, 38.159970)
	([749, 1501]	[749, 1559]

North9	(140.962417, 38.159970)	(140.965747, 38.159970)
	([749, 1561]	[749, 1619]

North10	(140.965840, 38.159970)	(140.969170, 38.159970)
	([749, 1621]	[749, 1679]

North11	(140.969262, 38.159970)	(140.970002, 38.159970)
	([749, 1681]	[749, 1694]

South1	(140.900720, 38.130000)	(140.900720, 38.130000)
	([83, 480]	[83, 480]

South2	(140.907657, 38.130000)	(140.907657, 38.130000)
	([83, 602]	[83, 602]

South3	(140.921440, 38.130000)	(140.921532, 38.130000)
	([83, 843]	[83, 845]

South4	(140.929950, 38.130000)	(140.930412, 38.130000)
	([83, 993]	[83, 1001]

South5	(140.941327, 38.130000)	(140.944658, 38.130000)
	([83, 1192]	[84, 1250]

South6	(140.944750, 38.130000)	(140.948080, 38.130000)
	([84, 1252]	[84, 1310]

South7	(140.948172, 38.130000)	(140.951503, 38.130000)
	([84, 1312]	[84, 1370]

South8	(140.951595, 38.130000)	(140.954925, 38.130000)
	([84, 1372]	[84, 1430]

South9	(140.955017, 38.130000)	(140.958348, 38.130000)
	([84, 1432]	[84, 1490]

South10	(140.958440, 38.130000)	(140.961770, 38.130000)
	([84, 1492]	[84, 1550]

South11	(140.961862, 38.130000)	(140.965193, 38.130000)
	([84, 1552]	[84, 1610]

South12	(140.965285, 38.130000)	(140.968615, 38.130000)
	([84, 1612]	[84, 1670]

South13	(140.968707, 38.130000)	(140.970002, 38.130000)
	([84, 1672]	[84, 1695]

East1	(140.970002, 38.130093)	(140.970002, 38.133423)
	([86, 1695]	[160, 1695]

East2	(140.970002, 38.133515)	(140.970002, 38.136845)
	([162, 1695]	[236, 1695]

East3	(140.970002, 38.136938)	(140.970002, 38.140268)
	([238, 1695]	[312, 1694]

East4	(140.970002, 38.140360)	(140.970002, 38.143690)
	([314, 1694]	[388, 1694]

East5	(140.970002, 38.143783)	(140.970002, 38.147113)
	([390, 1694]	[464, 1694]

East6	(140.970002, 38.147205)	(140.970002, 38.150535)
	([466, 1694]	[540, 1694]

East7	(140.970002, 38.150628)	(140.970002, 38.153958)
	([542, 1694]	[616, 1694]

East8	(140.970002, 38.154050)	(140.970002, 38.157380)
	([618, 1694]	[692, 1694]


In [6]:
m1 = [i[0] for i in mn1]
m2 = [i[0] for i in mn2]
n1 = [i[1] for i in mn1]
n2 = [i[1] for i in mn2]

In [11]:
fig = plt.figure(figsize=(18,12))
b_plot = plt.plot([n1,n2],[m1,m2],'ko-')



In [7]: